import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import path from 'path'
import svgLoader from 'vite-svg-loader'
export default defineConfig({
  plugins: [vue(),vueJsx(),svgLoader({defaultImport: 'url' })],
  server: {
    cors: true,
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src'), // 将 @ 映射为 src 目录的绝对路径
      }
    },
    proxy: {
      "/api":{
        target: 'https://main.common.lan:8099/api/',
        changeOrigin: true,
        ws: true,
        secure: false,
        rewrite: (path) => path.replace(/^\/api/, ''),
        bypass(req, res, options) {
            res.setHeader("X-Req-Proxyurl", options.target );
          },
          configure: (proxy, options) => {
            // 配置后请求的真实接口地址在请求头x-real-url中
            proxy.on("proxyRes", (proxyRes, req) => {
              proxyRes.headers["x-real-url"] =
                new URL(req.url || "", options.target)?.href || "";
            });
          },
      }
    }
  }
})